package CaixaEletronico;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;


import com.mysql.jdbc.PreparedStatement;

public class MovimentacaoDao {
	private Connection connection;
	
	 public MovimentacaoDao() {
		    this.connection = new ConnectionFactory().getConnection();
		  }
		 

		public boolean insert(Movimentacao movimentacao) throws SQLException {
			String sql = "insert into tb_historico"
		     		+ "(ID,HISTORICO,DEBITO,CREDITO,SALDO)"
		     		+ "values(?,?,?,?,?)";

		     try {
		         
		         PreparedStatement stmt = (PreparedStatement) connection.prepareStatement(sql);
		         
		         
		         stmt.setInt(1,movimentacao.getId());
		         stmt.setString(2,movimentacao.getHistorico());
		         stmt.setDouble(3,movimentacao.getDebito());
		         stmt.setDouble(4,movimentacao.getCredito());
		         stmt.setDouble(5,movimentacao.getSaldo());
		         
		         
		         
		         stmt.execute();
		         stmt.close();
		     } catch (SQLException e) {
		         throw new RuntimeException(e);
		     }
			return true;
		}

		public void getAll(int id) throws SQLException {
			  
			  PreparedStatement stmt = (PreparedStatement) this.connection.prepareStatement("Select*from tb_historico WHERE ID = "+id);
			  
			  ResultSet rs = stmt.executeQuery();
			  
			   
			  while(rs.next()){
				 
				 System.out.println("HISTORICO : "+rs.getString("HISTORICO"));
				 System.out.println("DEBITO : "+rs.getDouble("DEBITO"));
				 System.out.println("CREDITO : "+rs.getDouble("CREDITO"));
				 System.out.println("SALDO : "+rs.getDouble("SALDO"));
				 System.out.println();
				 
			  }
			  rs.close();
			  stmt.close();
			
			
		}

		public void disconnect() throws SQLException {
			this.connection.close();
			
		}	
}

